package com.snow.campuslink.bbs.controller;

import com.snow.campuslink.annotation.RequestLog;
import com.snow.campuslink.bbs.converter.dto.SearchConditionDto;
import com.snow.campuslink.bbs.converter.dto.SelectBbsPostDto;
import com.snow.campuslink.bbs.converter.dto.UpdateBbsPostActionCountDto;
import com.snow.campuslink.bbs.entity.BbsPost;
import com.snow.campuslink.bbs.service.IBbsPostService;
import com.snow.campuslink.project.BaseRestController;
import com.snow.campuslink.project.constant.Enum.ModuleEnum;
import com.snow.campuslink.project.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static com.snow.campuslink.utils.ParamCheckUtil.checkValidResult;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gaosl
 * @since 2021-02-10
 */
@RestController
@RequestMapping("/bbs/bbs-post")
public class BbsPostController  extends BaseRestController<IBbsPostService,BbsPost> {
    @Resource
    IBbsPostService bbsPostService;

    @ApiOperation(value = "搜索：根据查询关键词和帖子话题类型搜索相关帖子")
    @RequestLog(module = ModuleEnum.BBS_POST,description = "查询校园论坛帖子")
    @PostMapping("searchBbsPost")
    public Result searchBbsPost(@Validated @RequestBody SearchConditionDto searchConditionDto, BindingResult result){
        checkValidResult(result);
        List<SelectBbsPostDto> list = bbsPostService.selectBbsPost(searchConditionDto);
        return Result.success().data(list);
    }

    @ApiOperation("Feign接口")
    @PutMapping("updateActionCount")
    public void updateActionCount(@Validated @RequestBody UpdateBbsPostActionCountDto updateBbsPostActionCountDto, BindingResult result){
        checkValidResult(result);
        bbsPostService.updateActionCount(updateBbsPostActionCountDto);
    }
}

